<?php
/**
 * /BMS sn码查询
 *
 * @author sunjing@shopex.cn
 * @time 2017/12/7 11:48:33
 */
class erpapi_wms_matrix_jd_request_order extends erpapi_wms_request_order
{
  
    public function order_query($sdf){
        $order_bn = $sdf['order_bn'];

        $title = $this->__channelObj->wms['channel_name'] . 'SN码查询';

        $params = $this->_format_query_params($sdf);

        $branch_relationObj = app::get('wmsmgr')->model('branch_relation');
        $branch_relation    = $branch_relationObj->dump(array('wms_id'=>$this->__channelObj->wms['channel_id'],'sys_branch_bn'=>$sdf['branch_bn']));

        if ($branch_relation){
            $params['query_type'] = $branch_relation['querytype'] ? $branch_relation['querytype'] : '2';
        }
        $rs = $this->__caller->call(WMS_BMS_SNINFO_QUERY, $params, null, $title, 10, $order_bn);

        if($rs['rsp'] == 'succ') {
            //获取成功SN码后查询发货结果

            $sn_list = $this->_deal_query_result($rs['data']);
            return $sn_list;
           

        }

    }

   
    protected function _format_query_params($sdf){
        $params = array(

            'tid'               =>  $sdf['order_bn'],
            'bill_type'         =>  $sdf['bill_type'] ? $sdf['bill_type'] : '24',
            'page_no'           =>  '1',
            'page_size'         =>  '10',
            'query_type'        =>  '2',

        );
        
        return $params;
    }

    protected function _deal_query_result($data){
        $data = json_decode($data,true);
        $sninfolist = $data['msg']['serialNumbers'];
        $materialObj = app::get('material')->model('basic_material');
        $wms_id = $this->__channelObj->wms['channel_id'];
        $sn_list = array();
        foreach($sninfolist as $sn){
            $item_code = $sn['goodsNo'];
            $foreignsku = app::get('console')->model('foreign_sku')->dump(array('wms_id'=>$this->__channelObj->wms['channel_id'],'outer_sku'=>$item_code));

            $sn_list[] = array(
                'bn'            =>  $foreignsku['inner_sku'],

                'product_id'    =>  $foreignsku['inner_product_id'],
                'serial_number' =>  $sn['serialNumber'],

            );
        }

        return $sn_list;
    }


}